package org.example.ftp.controller;

import com.alibaba.fastjson.JSON;
import org.example.ftp.entity.TestEnum;
import org.example.ftp.entity.User;
import org.example.ftp.service.TestEnumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/testenum")
public class TestEnumController {

    @Autowired
    private TestEnumService testEnumService;
    @PostMapping("/add")
    public void add(@RequestBody TestEnum testEnum) {
        testEnumService.add(testEnum);
    }

    @PostMapping("/get/{id}")
    public void query(@PathVariable("id") int userId,
                      @RequestParam("id") int uid,
                      TestEnum testEnum
                      ) {
        TestEnum testEnum1 = testEnumService.query(userId);
        System.out.println(testEnum1);
    }

    // json
    @PostMapping("/addjson")
    public void addjson(@RequestBody TestEnum testEnum) {
        User user = new User();
        user.setUserName("张三");
        user.setUserSex("男");
        user.setAge(19);
        String str = JSON.toJSONString(user);
        testEnum.setInfo(str);
        testEnumService.addjson(testEnum);
    }
    // 分页
    @PostMapping("/page/{currentPage}/{pageSize}")
    public void page(@PathVariable("currentPage") int currentPage,
                     @PathVariable("pageSize") int pageSize) {
        currentPage = (currentPage -1) * pageSize;
        List<TestEnum> testEnums = testEnumService.page(currentPage,pageSize);
        System.out.println(testEnums);
    }

}
